class Solution
{
public:
    int minimumCardPickup(vector<int> &cards)
    {
        unordered_map<int, int> lastOccur;
        int n = cards.size();
        int minToPick = n + 1;
        for (int i = 0; i < n; ++i)
        {
            if (lastOccur.count(cards[i]))
            {
                minToPick = min(minToPick, i - lastOccur[cards[i]] + 1);
            }
            lastOccur[cards[i]] = i;
        }
        if (minToPick > n)
        {
            return -1;
        }
        else
        {
            return minToPick;
        }
    }
};